package com.hsnn.medstgmini.util;


import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.apache.log4j.Logger;
import org.springframework.web.context.ContextLoaderListener;

import com.hsnn.medstgmini.crypto.KeyStoreUtil;
import com.yspa.yspa.util.PushContentTask;

public class SystemInitListener extends ContextLoaderListener implements ServletContextListener {
    
	private static final Logger log = Logger.getLogger(SystemInitListener.class);
	
	public void contextInitialized(ServletContextEvent sce) {
		String realPath = sce.getServletContext().getRealPath("/");
		
		realPath = realPath.replaceAll("\\\\", "/");
		System.setProperty("realPath", realPath);
		sce.getServletContext().setAttribute("realPath", realPath);

		String ctx = sce.getServletContext().getContextPath();
		System.setProperty("ctx", ctx);
		sce.getServletContext().setAttribute("ctx", ctx);

		//If keystore file not exits, abort the startup.
		if (!KeyStoreUtil.keyStoreExits(sce.getServletContext().getRealPath("/WEB-INF/keystore/sysKeyStore"))) {
			log.error("Key store file not exist, abort start up !");
			System.exit(-1);
		}
		//注掉
//		new Thread(new Runnable() {
//			@Override
//			public void run() {
//				DicSysUtil.init();
//			}
//		}).start();
//		
		new Thread(new Runnable() {
			public void run() {
				PushContentTask.getContent();
			}
		}).start();
	}

	@Override
	public void contextDestroyed(ServletContextEvent sce) {

	}

}
